import React, { Component } from 'react'
import {SOneGoods} from "../../styled/shoppingCart";
import confirm from 'antd/lib/modal/confirm';
import Password from 'antd/lib/input/Password';
import { apilink } from '../../api/apilink';
import { withRouter } from 'react-router-dom';

class oneorder extends Component {
    constructor(props){
        super(props)
        this.state={
            payStatus:""
        }
    }
    //判断支付还是发货，显示。 点击支付改状态
    pay(){
        console.log(this.props.orderInfo.payStatus)
        //未支付 发送请求支付
        if(Number(this.props.orderInfo.payStatus) === 0){
            let password=prompt("请输入支付密码")
            if(password){
                let usp = new URLSearchParams();
                    usp.append("userId",sessionStorage.getItem("userId"));
                    usp.append("listGoodsId",this.props.orderInfo.listGoodsId);
                    usp.append("payStatus",1)
                apilink("/api/uppay_status","post",usp).then((ok)=>{
                    console.log(ok)
                    console.log(password);
                    if(ok.data === "pay_success"){
                        this.props.history.push("/paySuccess")

                    }
                }).catch((err)=>{
                    console.log(err)
                })

            }else{
                this.props.history.push("/myself")
            }
        }
            
        if(Number(this.props.orderInfo.payStatus)=== 1 && this.props.orderInfo.wuliu){
            alert("查看物流信息");
            this.props.history.push({pathname:"/myself/wuliu",query:{number:this.props.orderInfo.wuliu}})
        }else 
        if(Number(this.props.orderInfo.payStatus)=== 1){
                alert("请耐心等待发货");
                
        }
    }
    //点击跳转到订单详情页面  存store 在获取
    // orderDetails(){
    //     this.props.history.push("/orderDetails");
    // }
    render() {
        let {color,detailsImg, goodsChecked, id, kind, listGoodsId, payStatus,listGoodsNum, mainImg, price, productData, productInfo, productNumber, title, totalsMoney, userId} = this.props.orderInfo
        return (
                <SOneGoods>
            <div>
                {/* // onClick={this.orderDetails.bind(this)} */}
            <div className="bigbox contentorder">
                
                <div className="img">
                    <img src={mainImg} alt=""/>
                </div>
                <div className="info"> 
                    <div>
                        <h3>{`${title} ${kind.split(",")[0]} ${color} ${productData} ${productInfo}`}</h3>
                        <p className="num">产品编号：<span>{productNumber}</span></p>
                    </div>
                </div>
                <div className="price">
                    <p>单价：<i> {price}￥</i></p>
                    <em className="goodsNumber"> x{listGoodsNum}</em>
                    
                    <b>小计： <i>{price * listGoodsNum}</i></b>
                    <button onClick={this.pay.bind(this)}>{Number(payStatus)?"等待发货":"付款"}</button>
                </div>
            </div>
            </div>
            </SOneGoods>
        )
    }
}
export default withRouter(oneorder)